package gui;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.*;

import bot.*;

public class AreaSidePanelButton extends JButton{

	/**
	 * Default Serialization
	 */
	private static final long serialVersionUID = 1L;
	private JTextField url;
	private JTextField date;
	
	private PageGenerator page;
	
	public AreaSidePanelButton(JTextField textCity, JTextField textDate){
		super("Area Side Panel");
		url = textCity;
		date = textDate;
		page = new PageGenerator();
		
		addMouseListener(new MouseListener(){
			@Override
			public void mouseClicked(MouseEvent arg0) {
				boolean referenceType = false;
				if (arg0.getButton() == MouseEvent.BUTTON1){
					referenceType = true;
				}
				
				try{
					//make sure input is valid
					if (url.getText().equals("")){
						throw new IllegalArgumentException();
					}
					City choosen = new City(url.getText(), BotGui.data);
					//put the population info in the paste buffer
					Util.setPasteBuffer(page.getAreaSidePanel(choosen, date.getText(), referenceType));
				}
				catch (IllegalArgumentException e){
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "Invaild city name");
				}
			}
			@Override
			public void mouseEntered(MouseEvent arg0){}
			@Override
			public void mouseExited(MouseEvent arg0){}
			@Override
			public void mousePressed(MouseEvent arg0){}
			@Override
			public void mouseReleased(MouseEvent arg0){}
		});
	}
}

